#include "SensorRegion.h"

SensorRegion::SensorRegion()
{
}

SensorRegion::~SensorRegion()
{

}

void SensorRegion::initSensorRegion(b2Vec2 stPoint, b2Vec2 ePoint)
{
    startPoint = stPoint;
    endPoint = ePoint;
    priority = 0;
    isLocked = false;
}

bool SensorRegion::isContainVector(b2Vec2 vect)
{
    float vectLength = lengthOfVector(vect);
    float vectSin = vect.y / vectLength;
    float vectCos = vect.x / vectLength;

    if ((startPoint.y < endPoint.y) && (vectSin < startPoint.y || vectSin > endPoint.y)) {
        return false;
    }
    if ((startPoint.y > endPoint.y) && (vectSin > startPoint.y || vectSin < endPoint.y)) {
        return false;
    }

    if ((startPoint.x < endPoint.x) && (vectCos < startPoint.x || vectCos > endPoint.x)) {
        return false;
    }
    if ((startPoint.x > endPoint.x) && (vectCos > startPoint.x || vectCos < endPoint.x)) {
        return false;
    }

    return true;
}
